$(function () {
    $("input[type='password'][data-eye]").each(function (i) {
        let $this = $(this);

        $this.wrap($("<div/>", {
            style: 'position:relative'
        }));
        $this.css({
            paddingRight: 60
        });
        $this.after($("<div/>", {
            html: '显示密码',
            class: 'btn btn-primary btn-sm',
            id: 'passeye-toggle-' + i,
            style: 'position:absolute;right:10px;top:50%;transform:translate(0,-50%);padding: 2px 7px;font-size:12px;cursor:pointer;'
        }));
        $this.after($("<input/>", {
            type: 'hidden',
            id: 'passeye-' + i
        }));
        $this.on("keyup paste", function () {
            $("#passeye-" + i).val($(this).val());
        });
        $("#passeye-toggle-" + i).on("click", function () {
            if ($this.hasClass("show")) {
                $this.attr('type', 'password');
                $this.removeClass("show");
                $(this).removeClass("btn-outline-primary");
            } else {
                $this.attr('type', 'text');
                $this.val($("#passeye-" + i).val());
                $this.addClass("show");
                $(this).addClass("btn-outline-primary");
            }
        });
    });
});

$(document).ready(function () {
    let student_name = $.cookie('student_name');
    let password = $.cookie('asdf');
    let remember = $.cookie("remember");
    if (student_name != null && password != null) {
        $("#email").val(student_name);
        $("#password").val(password);
        $("#remember").attr("checked", true)
    }
});

// function login() {
//     const student_name = $("#email").val();
//     const password = $("#password").val();
//     let remember;
//     remember = !$("#remember").attr("checked");
//     $.ajax({
//         url: "/login/student",
//         type: "post",
//         data: {
//             username: student_name,
//             password: password,
//         },
//         success: function (data) {
//             let res = data;
//             if (res.code === 200 && res.message === '登录成功') {
//                 if (remember === true) {
//                     $.cookie('student_name', student_name,{path:"/login"});
//                     $.cookie('asdf', password,{path:"/login"});
//                     $.cookie('remember', remember,{path:"/login"});
//                 } else {
//                     $.cookie('student_name', null, {path: "/",expires:0});
//                     $.cookie('asdf', null, {path: "/",expires:0});
//                     $.cookie('remember', null, {path: "/",expires:0});
//                 }
//                 $.cookie('token', res.token);
//                 $(location).attr("href",document.referrer);
//             } else {
//                 alert("账号或密码错误");
//             }
//         },
//         error: function () {
//             alert("服务器错误!")
//         }
//     })
// }
//
